﻿
@{
    Layout = "";
}
<h3>活动规则</h3>
<div class="panel panel-default" ng-controller="SpecialTopicController" ng-class="{ 'whirl standard': isLoading}">
    <div class="panel-heading">
        <div class="form-inline ng-pristine ng-valid">
            <div class="form-group">
                <input placeholder="关键字" class="form-control" type="text" ng-model="Keywords">
                <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()">
                    <span class="btn-label">
                        <em class="fa fa-search"></em>
                    </span>搜索
                </button>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-labeled btn-success" ng-click="edit(0)">

                    <span class="btn-label">
                        <em class="fa fa-plus"></em>
                    </span>新增
                </button>
            </div>
        </div>
    </div>
    <div class="panel-body">
        <div class="table-responsive">
            <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                @*<colgroup>
                        <col style="width: 15%" />
                        <col style="width: 20%" />
                        <col style="width: 20%" />
                        <col style="width: 15%" />
                        <col style="width: 15%" />
                        <col style="width: 15%" />
                    </colgroup>*@
                <tbody>
                    <tr ng-repeat="model in $data">
                        <td data-title="'规则ID'" class="text-center">{{model.ID}}</td>
                        <td data-title="'规则类型'" class="text-center">{{model.RuleType==0?"一分钱活动":"降拼活动"}}</td>
                        <td data-title="'规则内容'" class="text-center">{{model.RuleContent}}</td>
                       
                        <td data-title="'操作'" nowrap="nowrap" class="text-center">
                            <button type="button" ng-click="remove($index,model)" class="btn btn-sm btn-danger" title="删除">
                                <em class="fa fa-trash-o"></em>
                            </button>
                            <button type="button" ng-click="edit(model.ID)" class="btn btn-sm btn-info"  title="编辑">
                                <em class="fa fa-edit"></em>
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <script type="text/ng-template" id="modalDialogId">
        <div class="ngdialog-message text-center">
            <h3>确定要删除吗?</h3>
            <p>删除后不可恢复!</p>
            <br />
            <button type="button" ng-click="confirm()" class="btn btn-primary mr">确认</button>
            <button type="button" ng-click="closeThisDialog('button')" class="btn btn-default">取消</button>
        </div>
    </script>
</div>
<script>
    App.controller('SpecialTopicController', [
    '$scope', '$resource', '$state', '$route', 'ngDialog', '$http', 'ngTableParams', 'ngTableDataService', 'Notify',
    function ($scope, $resource, $state, $route, ngDialog, $http, ngTableParams, ngTableDataService, Notify) {
        'use strict';
        $scope.isLoading = true;
        $scope.tableParams = new ngTableParams({
            page: 1,
            count: 10,
            sorting: {
                ID: 'desc'     // 初始化排序
            }
        }, {
            getData: function ($defer, params) {
                $scope.isLoading = true;
                var requestParams = {
                    Skip: (params.page() - 1) * params.count(),
                    Take: params.count(),
                    Keywords: $scope.Keywords
                };
                $http.post('/Activity/GetActivitRuleyList', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                    .success(function (data, status) {
                        debugger
                        params.total(data.Total);
                        $defer.resolve(data.Results);
                        $scope.isLoading = false;
                    });
            }
        });

        $scope.edit = function (id) {
            $state.go('app.activityruleedit', { "id": id });
        }

      
        $scope.remove = function (index, model) {
            ngDialog.openConfirm({
                template: 'modalDialogId',
                className: 'ngdialog-theme-default'
            }).then(function (value) {
                $http.post("/Activity/DelActivityRule", { id: model.ID }).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        $scope.tableParams.data.splice(index, 1);
                        Notify.alert(returnData.data.msg, { status: 'success', timeout: 1000 });
                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning', timeout: 1000 });
                    }
                });
            }, function (reason) {
            }
            );
        }
      
    }
    ]);
</script>